home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / edit / VE-VAnim.lha / arexx / VisualAnim.rexx
OS/2 REXX Batch file  |  1999-02-07  |  10KB  |  582 lines

  1. /*
  2.  
  3.    v2.34 Visual Anim
  4.  
  5.    Marko Seppänen
  6.    marko.seppanen@wwnet.fi
  7.  
  8. */
  9.  
  10.  
  11. call addlib('rexxmathlib.library',0,-30,0)
  12. address IMAGEENGINEER
  13.  
  14. Options results
  15. signal on error            /* Setup a place for errors to go */
  16.  
  17. if arg()=0 then exit
  18. pic=arg(1)
  19.  
  20.  
  21. MARK pic PRIMARY
  22. PROJECT_INFO pic WIDTH
  23. width=result
  24. PROJECT_INFO pic HEIGHT
  25. height=result
  26.  
  27. 'PALETTE_SAVE' pic 'ram:tempfileforiepalette'
  28.  
  29.  
  30.  
  31. /*
  32.     . THE BEGINNING .
  33.                         */
  34.  
  35.  
  36. if exists("ie:prefs/visualanim.cfg") == "1" then
  37.   do
  38.     call open("temp","ie:prefs/visualanim.cfg","R")
  39.     values=readln("temp")
  40.     parse var values ok visual quality rend savedir space bg .
  41.     call close("temp")
  42.   end
  43. else
  44.   do
  45.     quality=0
  46.     visual=0
  47.     bg=1
  48.     savedir="ram:"
  49.     space=25
  50.     rend=1
  51.   end
  52.  
  53. ' FORM "Visual-Anim" "Use|Cancel"',
  54. ' CYCLE,"Visual","Bulge|Ripple|Twirl",'visual'',
  55. ' CYCLE,"Quality","Fast|Best",'quality'',
  56. ' CHECKBOX,"Adjust Render-options",'rend'',
  57. ' DIR,"SaveDir",'savedir'',
  58. ' INTEGER,"Space around",0,100,'space',SLIDER',
  59. ' CYCLE,"BG-color","Black|White|Guess",'bg''
  60.  
  61. values=result
  62. parse var values ok visual quality rend savedir space bg .
  63. savedir=strip(savedir,B,'"')
  64.  
  65. if ok = 0 then exit
  66.  
  67. call open("temp","ie:prefs/visualanim.cfg","W")
  68. res=writeln("temp",values)
  69. call close("temp")
  70.  
  71.  
  72. if bg=0 then bg="BLACK"
  73. if bg=1 then bg="WHITE"
  74. if bg=2 then bg="GUESS"
  75.  
  76.  
  77. /*
  78.     . BACKGROUND COLOR .
  79.                            */
  80.  
  81. if space>0 then do
  82.  
  83.   if exists("ie:arexx/addspace.rexx") == "0" then do
  84.     'REQUEST "AddSpace.rexx is missing!" "I will get it... sorry"'
  85.     exit
  86.   end
  87.   address command "rexx:rx ie:arexx/AddSpace.rexx" pic space bg
  88.  
  89.   PROJECT_LIST
  90.   xyz=result
  91.   pic2=subword(xyz,1,1)
  92.  
  93. end
  94.  
  95. else pic2=pic
  96.  
  97.  
  98.  
  99. /* ..HOW MANY FRAMES?.. */
  100.  
  101.  
  102. 'REQUEST "How many frames?" "8|12|18|24|Cancel"'
  103.  
  104. select
  105.  
  106.   when result=1 then framecount=8
  107.   when result=2 then framecount=12
  108.   when result=3 then framecount=18
  109.   when result=4 then framecount=24
  110.  
  111.   otherwise exit
  112.  
  113. end
  114.  
  115.  
  116.  
  117.  
  118. /* ..ADJUST RENDEROPTIONS?.. */
  119.  
  120. if space(rend,0) == "1" then do
  121.   'RENDER_GET "How would like pictures to be rendered?"'
  122.   if RC=5 then exit
  123.   renderoptions=result
  124. end
  125.  
  126.  
  127.  
  128. /* ..QUALITY.. */
  129.  
  130. if quality == "1" then q="BEST"
  131. else q="FAST"
  132.  
  133.  
  134.  
  135.  
  136. /* ----------------HERE IT STARTS----------------*/
  137.  
  138. select
  139.  
  140.  
  141.  
  142.  
  143.  
  144. /*..VISUAL BULGE..*/
  145.  
  146.   when visual == 0 then
  147.   do
  148.  
  149.     if exists("ie:prefs/visualanimbulge.cfg") == "1" then
  150.       do
  151.         call open("temp","ie:prefs/visualanimbulge.cfg","R")
  152.         values=readln("temp")
  153.         parse var values ok type origamount radius
  154.         call close("temp")
  155.       end
  156.     else
  157.       do
  158.         type=0
  159.         origamount=25
  160.         radius=trunc(width/4)
  161.       end
  162.  
  163.     'FORM "Visual Bulge settings" "Use|Cancel"',
  164.     ' CYCLE,"Type","Boom|Rubber|In|Out",'type'',
  165.     ' INTEGER,"Bulge",1,100,'origamount',SLIDER',
  166.     ' INTEGER,"Radius",0,'width','radius',SLIDER'
  167.  
  168.     values=result
  169.     parse var values ok type origamount radius
  170.  
  171.     if ok = 0 then
  172.     do
  173.       close pic2
  174.       exit
  175.     end
  176.  
  177.     call open("temp","ie:prefs/visualanimbulge.cfg","W")
  178.     res=writeln("temp",values)
  179.     call close("temp")
  180.  
  181.  
  182.     x=width/2+space
  183.     y=height/2+space
  184.     over=0
  185.  
  186.     origamount="-"origamount
  187.     radius=0
  188.     radiusmax=(max(width,height))/2
  189.     rad=radiusmax/framecount*2
  190.     am=abs(origamount)/framecount*4
  191.     amount=origamount-am
  192.  
  193.  
  194.     do counter=1 to framecount
  195.  
  196.       sini=sin((360/framecount*counter-1)*(3.14/180))
  197.       cosi=cos((360/framecount*counter-1)*(3.14/180))
  198.  
  199.       select
  200.  
  201.         when type == 0 then
  202.           do
  203.  
  204.             if over ~== "1" then
  205.             do
  206.               radius=radius+rad
  207.             end
  208.             else
  209.             do
  210.               radius=radius-rad
  211.             end
  212.  
  213.             if radius>radiusmax then over=1
  214.  
  215.             BULGE pic2 x y radius abs(amount) q
  216.  
  217.           end
  218.  
  219.         when type == 1 then
  220.           do
  221.  
  222.             if over ~== "1" then
  223.             do
  224.               amount=amount+am
  225.             end
  226.             else
  227.             do
  228.               amount=amount-am
  229.             end
  230.  
  231.             if amount>abs(origamount)-1 then over=1
  232.  
  233.             BULGE pic2 x y radiusmax amount q
  234.  
  235.           end
  236.  
  237.         when type == 2 then
  238.           do
  239.  
  240.             BULGE pic2 cosi*(width/4)+(width/2+space) sini*(height/4)+(height/2+space) radiusmax amount q
  241.  
  242.           end
  243.  
  244.         when type == 3 then
  245.           do
  246.  
  247.             BULGE pic2 cosi*(width/4)+(width/2+space) sini*(height/4)+(height/2+space) radiusmax abs(amount) q
  248.  
  249.           end
  250.  
  251.         otherwise exit
  252.  
  253.       end
  254.  
  255.       x1=result
  256.       visual="bulge"
  257.       call save()
  258.  
  259.     end
  260.  
  261.   end
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275. /*..VISUAL RIPPLE..*/
  276.  
  277.   when visual == 1 then
  278.   do
  279.  
  280.     if exists("ie:prefs/visualanimripple.cfg") == "1" then
  281.       do
  282.         call open("temp","ie:prefs/visualanimripple.cfg","R")
  283.         values=readln("temp")
  284.         parse var values ok type amp period
  285.         call close("temp")
  286.       end
  287.     else
  288.       do
  289.         type=0
  290.         amp=5
  291.         period=trunc(width/2)
  292.       end
  293.  
  294.     'FORM "Visual Ripple settings" "Use|Cancel"',
  295.     ' CYCLE,"Type","Simple|SimpleC|Boom|BoomC|Ripple|Swirl",'type'',
  296.     ' INTEGER,"Amplitude",1,359,'amp',SLIDER',
  297.     ' INTEGER,"Period",0,'width','period',SLIDER'
  298.  
  299.     values=result
  300.     parse var values ok type amp period
  301.  
  302.     ampadd=trunc((amp/framecount)*2)
  303.  
  304.     if ok = 0 then
  305.     do
  306.       close pic2
  307.       exit
  308.     end
  309.  
  310.     call open("temp","ie:prefs/visualanimripple.cfg","W")
  311.     res=writeln("temp",values)
  312.     call close("temp")
  313.  
  314.  
  315.     do counter=1 to framecount
  316.  
  317.       select
  318.  
  319.         when type == 0 then
  320.           do
  321.             RIPPLE pic2 width/2+space-5 0 amp period 360/framecount*counter-1 OUT q
  322.           end
  323.  
  324.         when type == 1 then
  325.           do
  326.             RIPPLE pic2 0 0 amp period 360/framecount*counter-1 OUT q
  327.           end
  328.  
  329.         when type == 2 then
  330.           do
  331.  
  332.  
  333.             if counter<(framecount/2)+2 then
  334.               amp=amp+ampadd
  335.             else
  336.               amp=amp-ampadd
  337.  
  338.             RIPPLE pic2 width/2+20 0 amp period 360/framecount*counter-1 OUT q
  339.           end
  340.  
  341.         when type == 3 then
  342.  
  343.           do
  344.             if counter<framecount/2+2 then
  345.               amp=amp+ampadd
  346.             else
  347.               amp=amp-ampadd
  348.  
  349.             RIPPLE pic2 0 0 amp period 360/framecount*counter-1 OUT q
  350.           end
  351.  
  352.         when type == 4 then
  353.           do
  354.             if counter<framecount/2+2 then
  355.               amp=amp+ampadd
  356.             else
  357.               amp=amp-ampadd
  358.  
  359.             RIPPLE pic2 width/2+20 0 amp period 360/framecount*counter-1 AROUND q
  360.           end
  361.  
  362.         when type == 5 then
  363.           do
  364.             RIPPLE pic2 width/2+20 height/2+space amp period 360/framecount*counter-1 AROUND q
  365.           end
  366.  
  367.         otherwise exit
  368.  
  369.       end
  370.  
  371.       x1=result
  372.       visual="ripple"
  373.       call save()
  374.  
  375.     end
  376.  
  377.   end
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385. /*..VISUAL TWIRL..*/
  386.  
  387.  
  388.   when visual == 2 then
  389.   do
  390.  
  391.     if exists("ie:prefs/visualanimtwirl.cfg") == "1" then
  392.       do
  393.         call open("temp","ie:prefs/visualanimtwirl.cfg","R")
  394.         values=readln("temp")
  395.         parse var values ok type radius origdegree
  396.         call close("temp")
  397.       end
  398.     else
  399.       do
  400.         type=0
  401.         radius=trunc(width/2)
  402.         origdegree=20
  403.       end
  404.  
  405.     'FORM "Visual Twirl settings" "Use|Cancel"',
  406.     ' CYCLE,"Type","Swing|Swing2|ShakeIt|ShakeIt2",'type'',
  407.     ' INTEGER,"Radius",1,'width','radius',SLIDER',
  408.     ' INTEGER,"Degree",1,'359','origdegree',SLIDER'
  409.  
  410.     values=result
  411.     parse var values ok type radius origdegree
  412.  
  413.     if ok = 0 then
  414.     do
  415.       close pic2
  416.       exit
  417.     end
  418.  
  419.     call open("temp","ie:prefs/visualanimtwirl.cfg","W")
  420.     res=writeln("temp",values)
  421.     call close("temp")
  422.  
  423.  
  424.     x=width/2+space
  425.     y=height/2+space
  426.     origdegree="-"origdegree
  427.  
  428.     radius=(max(width,height))/2
  429.     radiusmin=(min(width,height))/2
  430.     radius2=0
  431.     radiusmax=trunc(sqr(width**2+height**2))
  432.     rad=radiusmax/framecount
  433.  
  434.     deg=abs(4*origdegree)/(framecount)
  435.     degree=origdegree-deg
  436.     deg2=abs(2*origdegree)/(framecount)
  437.     degree2=0
  438.  
  439.  
  440.     do counter=1 to framecount
  441.  
  442.       sini=sin((360/framecount*counter-1)*(3.14/180))
  443.       cosi=cos((360/framecount*counter-1)*(3.14/180))
  444.  
  445.       select
  446.  
  447.         when type == 0 then
  448.           do
  449.  
  450.             if over ~== "1" then
  451.             do
  452.               degree=degree+deg
  453.             end
  454.             else
  455.             do
  456.               degree=degree-deg
  457.             end
  458.  
  459.             if degree>abs(origdegree)-deg then over=1
  460.  
  461.             TWIRL pic2 x y radius+50 degree q
  462.  
  463.           end
  464.  
  465.         when type == 1 then
  466.           do
  467.  
  468.             if over ~== "1" then
  469.             do
  470.               degree2=degree2+deg2
  471.             end
  472.             else
  473.             do
  474.               degree2=degree2-deg2
  475.             end
  476.  
  477.             if degree2>abs(origdegree)-deg2 then over=1
  478.  
  479.             radius2=radius2+rad
  480.  
  481.             TWIRL pic2 space space radius2 degree2 q
  482.  
  483.           end
  484.  
  485.         when type == 2 then
  486.           do
  487.  
  488.             TWIRL pic2 cosi*(width/4)+(width/2+space) sini*(height/4)+(height/2+space) radius abs(origdegree) q
  489.  
  490.           end
  491.  
  492.         when type == 3 then
  493.           do
  494.  
  495.             TWIRL pic2 cosi*(width/4)+(width/2+space) sini*(height/4)+(height/2+space) radiusmin abs(origdegree) q
  496.  
  497.           end
  498.  
  499.  
  500.         otherwise exit
  501.  
  502.       end
  503.  
  504.       x1=result
  505.       visual="twirl"
  506.       call save()
  507.  
  508.     end
  509.  
  510.   end
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521. /* THE END */
  522.  
  523.  
  524.   otherwise exit
  525.  
  526. end
  527.  
  528. if space~=0 then CLOSE pic2
  529.  
  530. exit
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539. /* ..SAVING.. */
  540.  
  541.  
  542. save:
  543.  
  544.       'PALETTE_LOAD' x1 'ram:tempfileforiepalette'
  545.  
  546.       if rend == "1" then do
  547.         'RENDER_SET' x1 renderoptions
  548.       end
  549.       else do
  550.         'RENDER_SET' x1 "0 167940 8 255 0 1"
  551.       end
  552.  
  553.       RENDER x1
  554.  
  555.       if counter <10 then counter=insert("0",counter)
  556.       filename=savedir''visual''"."counter
  557.  
  558.       SAVE x1 '"'filename'"' '"'ILBM CmpByteRun1'"'
  559.  
  560.       CLOSE x1
  561.  
  562.       return
  563.  
  564.  
  565. /*******************************************************************/
  566. /* This is where control goes when an error code is returned by IE */
  567. /* It puts up a message saying what happened and on which line     */
  568. /*******************************************************************/
  569. error:
  570. if RC=5 then do            /* Did the user just cancel us? */
  571.     IE_TO_FRONT
  572.     LAST_ERROR
  573.     'REQUEST "'||RESULT||'"'
  574.     exit
  575. end
  576. else do
  577.     IE_TO_FRONT
  578.     LAST_ERROR
  579.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  580.     exit
  581. end
  582.